﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OrderFrm.aspx.cs" Inherits="WebApp.OrderFrm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>工作单信息</title>
    <link rel="stylesheet" type="text/css" href="css/newStyle.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/icon.css" />

    <script type="text/javascript" src="js/common.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery-1.8.0.min.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/locale/easyui-lang-zh_CN.js"></script>

    <script type="text/javascript">
        var PageSize = 20;
        //页面加载
        $(window).load(function() {
            initData();
            initGrid();
        });

        $(window).resize(function() {
            $('#tb').datagrid('resize');
        });

        function doSearch(pageNumber, sort, order) {
            if (pageNumber > 0)
                pageNumber = pageNumber - 1; //从0开始
            var params = getParams(pageNumber, sort, order);
            $('#tb').datagrid('reload', params);

            //            $.post('JSONHandler.ashx', params, function(theback) {
            //                $('#tb').datagrid('loadData', theback);
            //            }, "json");
        }

        //$("#tb").datagrid('getPager').pagination({ pageSize: params.rows, pageNumber: params.page });

        function getParams(pageNumber, sort, order) {
            //var cc = $('#qClient').combogrid('getValue');
            var c = '';
            var qClient = $('#qClient').combogrid('grid').datagrid('getSelected');
            if (qClient)
                c = qClient.fullName;
            return {
                DataType: 'Order',
                deleteFlag: $('#qDeleteFlag').val(),
                orderCode: $('#qCode').val(),
                cCode: $('#qCCode').val(),
                sDate: $('#qSDate').datebox('getValue'),
                eDate: $('#qEDate').datebox('getValue'),
                orderStatus: $('#qOrderStatus').combobox('getValue'),
                agent: $('#qAgent').combogrid('getValue'),
                bizMan: $('#qBizMan').combogrid('getValue'),
                stowageMethod: $('#qStowageMethod').combobox('getValue'),
                clientName: c,
                isDrawback: $('#qDrawBack').val(),
                customsStatus: $('#qCustomsStatus').combobox('getValue'),
                checkOffCode: $('#qCheckOffCode').val(),
                caseCode: $('#qCaseCode').val(),
                pageSize: PageSize,
                pageIndex: pageNumber,
                sort: sort,
                order: order
            };
        }

        function booleanFormat(val, rec) {
            if (val == true) {
                return "是";
            }
            else {
                if (val == false)
                    return "否";
                else
                    return val;
            }
        }

        //加载表格datagrid
        function initGrid() {

            var params = getParams(0);

            //加载数据
            $('#tb').datagrid({
                toolbar: '#menuBar',
                //width: 'auto',
                fit: true,
                fitColumns: true,
                //height: 'auto',
                singleSelect: true,
                striped: true,
                remoteSort: true,
                url: 'JSONHandler.ashx',
                //url: 'JSONHandler.ashx?DataType=Order&deleteFlag=&orderCode=&cCode=&sDate=&eDate=&orderStatus=&agent=&bizMan=&stowageMethod=&clientName=&isDrawback=&customsStatus=&checkOffCode=&caseCode=&pageSize=' + pSize + '&pageIndex=' + pIndex,
                queryParams: params,
                loadMsg: '数据加载中请稍后……',
                pagination: true,
                rownumbers: true,
                columns: [[
        { field: 'OrderId', title: '编号', align: 'center', hidden: true },
        { field: 'OrderCode', title: '作业单号', align: 'center', sortable: true },
        { field: 'CCode', title: '提单号', align: 'center', sortable: true },
        { field: 'StartPortName', title: '起运港', align: 'center', sortable: true },
        { field: 'ClientName', title: '委托方', align: 'center', sortable: true },
        { field: 'IsOffer', title: '交单', align: 'center', formatter: booleanFormat, sortable: true },
        { field: 'IsCheck', title: '查验', align: 'center', formatter: booleanFormat, sortable: true },
        { field: 'IsPass', title: '放行', align: 'center', formatter: booleanFormat, sortable: true },
        { field: 'IsNotice', title: '通知', align: 'center', formatter: booleanFormat, sortable: true },
        { field: 'OrderStatus', title: '工作状态', align: 'center', sortable: true },
        { field: 'CustomsStatus', title: '报关状态', align: 'center', sortable: true },
        { field: 'ApplyDate', title: '申报时间', align: 'center', formatter: Common.DateFormatter, sortable: true },
        { field: 'BizmanName', title: '业务员', align: 'center', sortable: true },
        { field: 'AgentName', title: '客服', align: 'center', sortable: true },
        { field: 'PassTime', title: '放行时间', align: 'center', formatter: Common.DateFormatter },
        { field: 'DeleteFlag', title: '取消', align: 'center', formatter: booleanFormat }
    ]], onDblClickRow: function(rowIndex, rowData) {
        editOrder();
    }, onLoadSuccess: function(data) {
    }, loadFilter: function(data) {
        if (data)
            return data;
        else
            return { "total": 0, "rows": [] };
    }, onSortColumn: function(sort, order) {
        doSearch(1, sort, order);
    }
            });

            /**
            * 为grid添加自己重新加载方法,解决带条件查询的时候分页栏不能回到首页问题
            */
            //            $.extend($.fn.datagrid.methods, {
            //                myreload: function(jq, newposition) {
            //                    return jq.each(function() {
            //                        //显示第一页数据   
            //                        $(this).datagrid("options").pageNumber = 1;
            //                        //分页栏上跳转到第一页   
            //                        $(this).datagrid('getPager').pagination({ pageNumber: 1 });
            //                        $(this).datagrid("reload", newposition);
            //                    });
            //                }
            //            });

            //var p = $('#tb').datagrid('getPager');

            $('#tb').datagrid('getPager').pagination({
                pageSize: PageSize, //每页显示的记录条数，默认为10   
                pageList: [10, 20, 30, 40, 50], //可以设置每页记录条数的列表   
                beforePageText: '第', //页数文本框前显示的汉字   
                afterPageText: '页    共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
                onBeforeRefresh: function() {
                },
                onRefresh: function(pageNumber, pageSize) {
                },
                onChangePageSize: function(pageSize) {
                    PageSize = pageSize;
                },
                onSelectPage: function(pageNumber, pageSize) {
                    doSearch(pageNumber);
                }
            });

        }

        function initData() {
            $('#qSDate').datebox('setValue', DateFormatter(new Date().DateAdd('m', -1)));
            $('#qEDate').datebox('setValue', DateFormatter(new Date().DateAdd2('d', 1)));
            $('#qOrderStatus').combobox('reload', 'JSONHandler.ashx?DataType=OrderStatus');

            $.getJSON("JSONHandler.ashx?DataType=StowageMethod", function(result) {
                $('#qStowageMethod').combobox('loadData', result);
            });

            $.getJSON("JSONHandler.ashx?DataType=CustomsStatus", function(result) {
                $('#qCustomsStatus').combobox('loadData', result);
            });

            $.getJSON("JSONHandler.ashx?DataType=User", function(result) {
                $('#qAgent').combogrid("grid").datagrid("loadData", result);
                $('#qBizMan').combogrid("grid").datagrid("loadData", result);
            });

            $.getJSON("JSONHandler.ashx?DataType=Client", function(result) {
                $('#qClient').combogrid("grid").datagrid("loadData", result);
            });
        }

        function resetAll() {
            $('#qOrderStatus').combobox('clear');
            $('#qAgent').combogrid('clear');
            $('#qOperator').combogrid('clear');
            $('#qClient').combogrid('clear');
            $('#qStowageMethod').combobox('clear');
            $('#qCustomsStatus').combobox('clear');
        }

        function newOrder() {
            $('#winFrame').prop('src', 'EditOrderFrm.aspx');
            $('#winFrame').prop('style').height = '100%';
            $('#winFrame').prop('style').width = '100%';
            $('#win').window({
                fit: true,
                modal: true,
                resizable: true,
                collapsible: false,
                minimizable: false,
                maximized: true,
                title: '新建工作单'
            });
        }

        function editOrder() {
            var row = $('#tb').datagrid('getSelected');
            if (row) {
                var id = row.OrderId;
                $('#winFrame').prop('src', 'EditOrderFrm.aspx?OrderId=' + id);
                $('#winFrame').prop('style').height = '100%';
                $('#winFrame').prop('style').width = '100%';
                $('#win').window({
                    fit: true,
                    modal: true,
                    resizable: true,
                    collapsible: false,
                    minimizable: false,
                    maximized: true,
                    title: '编辑工作单'
                });
            }
        }

        function cancelOrder() {
            var row = $('#tb').datagrid('getSelected');
            if (row) {
                $.messager.confirm('提示', '确认取消该工作单吗?', function(r) {
                    if (r) {
                        var id = row.OrderId;
                        WebApp.OrderFrm.CancelOrder(id, function callback(p) {
                            if (p.error) {
                                $.messager.alert('异常消息', '提交取消异常,' + p.error.Message, 'error');
                                return;
                            }

                            var res = p.value;
                            if (res) {
                                var data = res.Data;
                                var msg = res.Msg;
                                if (msg)
                                    $.messager.alert('取消工作单异常', msg, 'error');
                                else {
                                    if (data == true) {
                                        $.messager.alert('消息', '工作单信息已取消!', 'info');
                                        doSearch(0);
                                        //$('#tb').datagrid('selectRow',row.index);
                                    }
                                    else
                                        $.messager.alert('取消工作单失败', msg, 'error');
                                }
                            }
                        });
                    }
                });
            }
        }               
    </script>

</head>
<body style="padding: 5px;">
    <form id="Form1" method="post" runat="server">
    </form>
    <div class="easyui-layout" fit="true">
        <div data-options="region:'north'">
            <div id="searchBar" style="padding: 5px; height: auto">
                <span>接单时段：</span>
                <input id="qSDate" class="easyui-datebox" data-options="formatter:DateFormatter,parser:DateParser"
                    style="width: 100px" />至
                <input id="qEDate" class="easyui-datebox" style="width: 100px" />
                <span>流程状态：</span><input class="easyui-combobox" id="qOrderStatus" data-options="valueField:'Value',textField:'Name'"
                    style="width: 100px;">
                <span>装柜形式：</span><input class="easyui-combobox" id="qStowageMethod" data-options="valueField:'id',textField:'name'"
                    style="width: 100px;">
                <span>报关状态：</span><input class="easyui-combobox" id="qCustomsStatus" data-options="valueField:'Value',textField:'Name'"
                    style="width: 100px;">
                <span>是否退税：</span><select class="easyui-combobox" id="qDrawBack" style="width: 100px;">
                    <option value="">所有</option>
                    <option value="1">是</option>
                    <option value="0">否</option>
                </select>
                <br />
                <br />
                <span>单据状态：</span><select class="easyui-combobox" id="qDeleteFlag" style="width: 100px;">
                    <option value="">所有</option>
                    <option value="0">正常状态</option>
                    <option value="1">取消状态</option>
                </select>
                <span>客服：</span><input class="easyui-combogrid" id="qAgent" style="width: 150px"
                    data-options="  
            panelWidth: 150,  
            idField: 'id',  
            textField: 'userName',
            columns: [[   
                {field:'userName',title:'名称',width:150}               
            ]],  
            fitColumns: true  
        ">
                <span>业务：</span><input class="easyui-combogrid" id="qBizMan" style="width: 150px"
                    data-options="  
            panelWidth: 150,  
            idField: 'id',  
            textField: 'userName',
            columns: [[   
                {field:'userName',title:'名称',width:150}               
            ]],  
            fitColumns: true  
        ">
                <span>委托方：</span><input class="easyui-combogrid" id="qClient" style="width: 200px"
                    data-options="  
            panelWidth: 200,  
            idField: 'id',  
            textField: 'fullName', 
            columns: [[  
                {field:'fullName',title:'名称',width:200}        
            ]],  
            fitColumns: true  
        ">
                <br />
                <br />
                <span>作业号：</span><input type="text" style="width: 100px" id="qCode">
                <span>提单号：</span><input type="text" style="width: 100px" id="qCCode">
                <span>核销单号：</span><input type="text" style="width: 100px" id="qCheckOffCode">
                <span>柜号：</span><input type="text" style="width: 100px" id="qCaseCode">
                &nbsp;&nbsp;<a href="#" class="easyui-linkbutton" iconcls="icon-search" onclick="doSearch(0);">
                    搜索</a> <a href="#" class="easyui-linkbutton" iconcls="icon-undo" onclick="resetAll();">
                        重置</a> <a href="#" class="easyui-linkbutton" iconcls="icon-add" onclick="newOrder()">
                            新增</a> <a href="#" class="easyui-linkbutton" iconcls="icon-edit" onclick="editOrder()">
                                编辑</a> <a href="#" class="easyui-linkbutton" iconcls="icon-remove" onclick="cancelOrder()">
                                    删除</a>
            </div>
            <div id="menuBar" style="padding: 5px; height: auto">
                </div>
        </div>
        <div data-options="region:'center'" style="position: relative;">
            <table class="easyui-datagrid" id="tb">
            </table>
        </div>
    </div>
    <div id="win" style="text-align: center">
        <iframe id="winFrame" src="" style="width: 100%; height: 100%" frameborder="0" scrolling="no">
        </iframe>
    </div>
</body>
</html>
